package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.RawMaterialMapper;
import com.dmpp.mes.dao.SemiProductsMapper;
import com.dmpp.mes.parameterInfo.RawMaterial;
import com.dmpp.mes.parameterInfo.SemiProducts;
import com.dmpp.mes.service.RawMaterialService;
import com.dmpp.mes.service.SemiProductsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "SemiProductsService")

public class SemiProductsServiceImpl implements SemiProductsService {

    @Autowired
    private SemiProductsMapper mapper;

    @Override
    public ResponseData findAll(SemiProducts semiProducts) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(semiProducts));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findById(String id) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findById(id));
        return responseData;
    }

    @Override
    public ResponseData insert(SemiProducts semiProducts) {
        ResponseData responseData = new ResponseData();
        SemiProducts semiProducts1= mapper.findById(semiProducts.getId());
        if (semiProducts1==null){
            mapper.insert(semiProducts);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateById(SemiProducts semiProducts) {
        ResponseData responseData = new ResponseData();
        mapper.updateById(semiProducts);
        return responseData;
    }

    @Override
    public ResponseData deleteById(String id) {
        ResponseData responseData = new ResponseData();
        mapper.deleteById(id);
        return responseData;
    }

    @Override
    public ResponseData altogether(SemiProducts semiProducts) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.altogether(semiProducts));
        return responseData;
    }
}
